----------------------------------------------------------------------------------
-- Company: 
-- Engineer: 
-- 
-- Create Date:    18:50:12 10/06/2013 
-- Design Name: 
-- Module Name:    unsigned_32_comparator - Behavioral 
-- Project Name: 
-- Target Devices: 
-- Tool versions: 
-- Description: 
--
-- Dependencies: 
--
-- Revision: 
-- Revision 0.01 - File Created
-- Additional Comments: 
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.std_logic_signed.ALL;
use IEEE.NUMERIC_STD.ALL;

entity div_base_4_unsigned_32_comparator is
	PORT (
	A : in STD_LOGIC_VECTOR(31 downto 0);
	B : in STD_LOGIC_VECTOR(31 downto 0);
	
	is_ge : out STD_LOGIC; -- '1' if A >= B
	diff : out STD_LOGIC_VECTOR(31 downto 0) --- A-B, if A > B. if not, undefined (can be anything)
	);
end div_base_4_unsigned_32_comparator;

architecture Behavioral of div_base_4_unsigned_32_comparator is
begin
	process(A, B)
		variable post_subtract : STD_LOGIC_VECTOR(31 downto 0);
	begin
		post_subtract := std_logic_vector(unsigned(A) - unsigned(B));
		if ((A(31) = B(31))) then
			--post_subtract := std_logic_vector(unsigned("1"&A(30 downto 0)) - unsigned("0"&B(30 downto 0)));
			--is_ge <= post_subtract(31);
			--diff <= "0"&post_subtract(30 downto 0);
			is_ge <= not post_subtract(31);
			diff <= post_subtract;
		elsif ((A(31) ='1' and B(31)='0')) then
			--post_subtract := std_logic_vector(unsigned(A) - unsigned(B));
			is_ge <= '1';			-- Definitely greater as long A's MSB is greater than B
			diff <= post_subtract; -- Subtracting  
		else
			is_ge <= '0'; 			-- Not greater
			diff <= x"00000000"; -- Do not bother about diff, not important
		end if;
	
	end process;


end Behavioral;

